Links can do many things. They can point to email addresses, ftp addresses, other parts of the same site, or different sites altogether. And we don't really know which of these a little bit of underlined blue text is until we move the mouse over it and inspect the url, or possibly until we click the link.
It would be nice to be able to code our links so that users could determine what kind of links they were simply by looking at them. With style sheets, and classes, we can do just that. In fact, by combining the link selectors (technically called pseudo class selectors) like A:hover (see Chapter 7) with class selectors, we can create a style for classes of links in different states.
That's just what we are going to do in this lesson.
Firstly, let's think about the different classes of link you might have on a page.
Check at the end of the lesson for my thoughts
What are the four link state selectors we saw in Setting Up Links?
Here is the tricky part. We need to combine the link selectors with class selectors. To do this, we use the following form
A.class-name:link-state
for example
A.ftp:link
To create a class based pseudo class selector using Style Master
1. choose
from the menu2. in the pop-up menu of the dialog box, choose
3. the link pseudo class selector editor opens
4. choose
in the pop-up menu at the top of the window5. enter the name of the class in the text field, and choose the state in the pop-up menu to the right of it
6 click
Create the following selectors
Got the hang of that? Now we want to create rules to select and apply style to each of these classes of link in our page.
See my example answers at the end of the lesson, after you've created your rules, of course.
Lastly, we need to mark up these classes in our web page.
My examples are at the end of the lesson.
Now, save the style sheet and the web page. Open the page in your browser (IE 4 if you have it, just so you can delight in the hover effect).
In this lesson we got pretty sophisticated, combining the pseudo class selector (link selector) with the class selector. We've come a long way.
Next we will look at an important issue, how to ensure style sheets based sites look OK in older browsers.
onsite links that point to other parts of this site, that is relative links
offsite links that point to sites other than this one, that is absolute links
ftp links to ftp site for downloading files
email for mailto links
and I'm sure you could think of others.
A.email:active
A.ftp:hover
A.offsite:visited
A.onsite:link {background-color: #ccffcc}
A.onsite:visited {background-color: #99ffcc}
A.onsite:active {background-color: #66ffcc}
A.onsite:hover {background-color: #33ffcc}
A.offsite:link {background-color: #ffccff}
A.offsite:visited {background-color: #ff99ff}
A.offsite:active {background-color: #ff99ff}
A.offsite:hover {background-color: #ff66ff}
A.ftp:link {background-color: #ffffcc}
A.ftp:visited {background-color: #ffff99}
A.ftp:active {background-color: #ffff66}
A.ftp:hover {background-color: #ffff33}
A.email:link {background-color: #00ffff}
A.email:visited {background-color: #66ffff}
A.email:active {background-color: #99ffff}
A.email:hover {background-color: #ccffff}
<HTML>
<HEAD>
<TITLE>Choux</TITLE>
<LINK REL=STYLESHEET TYPE="text/css" HREF="core-style.css">
</HEAD>
<BODY>
<H1>Classic Patisserie Recipes</H1>
<H2>Pastry Cream</H2>
<P>Also known as creme patissiere, this is the traditional filling
for <A class="onsite" HREF="fruit_tarts.html">fresh fruit tarts</A>. It is also used
to fill <A class="onsite" HREF="choux_puffs.html">choux puffs</A>.</P>
<H3>Ingredients</H3>
<P>2 cups milk</P>
<P>1 vanilla bean</P>
<P>6 egg yolks</P>
<P>175g castor sugar</P>
<P>50g cornflour</P>
<H3>Method</H3>
<P>Scald milk with vanilla bean. Beat egg yolks with cornflour until
thick. Pour in milk and whisk until quite smooth.</P>
<H1>More Information</H1>
<P>to contact the author, email me on
<A class="email" HREF="mailto:john@masterchef.org">john@masterchef.org</A></P>
<P>to download all my recipes in acrobat format,
<A class="ftp" HREF="ftp://ftp.masterchef.org/recipes.pdf">click here</A></P>
<P>for other recipes, see biodynamic recipes from
<A class="offsite" HREF="http://www.biodyn.nu">http://www.biodyn.nu</A></P>
</BODY>
</HTML>